package com.cooldatasoft.service.impl;

import java.util.Date;
import java.util.List;

import com.cooldatasoft.base.RootServiceImpl;
import com.cooldatasoft.data.Person;
import com.cooldatasoft.data.User;
import com.cooldatasoft.service.UserService;

public class UserServiceImpl extends RootServiceImpl implements UserService{

	public User authenticate(User user) {
		if(user != null && user.getUsername()!= null && user.getPassword() != null){
			return getUserDAO().authenticate(user);
		}
		return null;
	}

	public Person get(Integer personId) {
		return getPersonDAO().get(personId);
	}

	public void deleteUserById(Integer entityId, User currentUser) {
		User userToBeDeleted = getUserDAO().get(entityId);		
		userToBeDeleted.setUpdateDate(new Date());
		userToBeDeleted.setUpdateUserId(currentUser.getId());
		userToBeDeleted.setDeleted(true);
		getUserDAO().saveOrUpdate(userToBeDeleted);
	}

	public List<User> getUserList() {
		return getUserDAO().find("from User WHERE deleted=false");
	}

	public User getUserById(Integer entityId) {
		return getUserDAO().get(entityId);
	}

	public void saveOrUpdate(User user) {
		getUserDAO().saveOrUpdate(user);
	}

}
